package com.ruoyi.web.controller.agoniappWeb;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.pojo.entity.Product;
import com.ruoyi.system.service.IAgoniProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/pages/product")
public class ProductWebController {

    @Autowired
    private IAgoniProductService agoniProductService;
    @GetMapping("/listProducts")
    public AjaxResult listProducts(){
        return AjaxResult.success(agoniProductService.listProducts());
    }


    @GetMapping("/listServiceProducts/{storeId}")
    public AjaxResult listServiceProducts(@PathVariable Long storeId) {
        // 假设你有一个 service 方法来获取对应的产品
        List<Product> products = agoniProductService.listServiceProducts(storeId);
        return AjaxResult.success(products);
    }

    //添加产品
    @PostMapping("/addProduct")
    public AjaxResult addProduct(@RequestBody Product product){
        return AjaxResult.success(agoniProductService.addProduct(product));
    }

    //修改产品
    @PutMapping("/updateProduct/{id}")
    public AjaxResult updateProduct(@PathVariable Long id, @RequestBody Product product){
        log.info("updateProduct id:{}, product:{}", id, product);
        int result = agoniProductService.updateProduct(id, product);
        if(result == 1){
            return AjaxResult.success("修改成功");
        }else{
            return AjaxResult.error("修改失败");
        }
    }




}
